﻿package tagul {

    public class StringHelper extends Object {

        public function StringHelper() {
            return;
        } // end function

        public function replace(param1:String, param2:String, param3:String):String {
            return param1.split(param2).join(param3);
        } // end function

        public function trim(param1:String, param2:String = " "):String {
            return this.trimBack(this.trimFront(param1, param2), param2);
        } // end function

        public function trimFront(param1:String, param2:String):String {
            param2 = this.stringToCharacter(param2);
            if (param1.charAt(0) == param2) {
                param1 = this.trimFront(param1.substring(1), param2);
            }
            return param1;
        } // end function

        public function trimBack(param1:String, param2:String):String {
            param2 = this.stringToCharacter(param2);
            if (param1.charAt((param1.length - 1)) == param2) {
                param1 = this.trimBack(param1.substring(0, (param1.length - 1)), param2);
            }
            return param1;
        } // end function

        public function stringToCharacter(param1:String):String {
            if (param1.length == 1) {
                return param1;
            }
            return param1.slice(0, 1);
        } // end function

    }
}
